#导包
from common.base import Base
from common.base import open_browser
import time
url = "http://ecshop.itsoso.cn/"
#创建类

class Goods_Page(Base):
    """封装表现层__制作定位器"""
    goods_loc = ("css selector", "div.goods-title>a")
    phone_loc=("link text","手机")
    office_loc=("link text","办公")
    computer_loc = ("link text", "电脑")
    cloth_loc = ("link text", "男装/女装")
    digit_loc=("link text","数码时尚")
    toy_loc=("link text","母婴/玩具")
    wine_loc = ("link text", "食品/酒类")
    sports_loc=("link text","运动/户外")



    def click_phone(self):

        self.click(self.phone_loc)

    def click_office(self):
        self.click(self.office_loc)

    def click_cloth(self):
        self.click(self.cloth_loc)

    def click_digit(self):
        self.click(self.digit_loc)

    def click_toy(self):
        self.click(self.toy_loc)

    def click_wine(self):
        self.click(self.wine_loc)

    def click_sports(self):
        self.click(self.sports_loc)


    def get_goods_titles(self):
    """获取所有商品标题"""
    goods_elements = self.find_elements(self.goods_loc)
    titles = []
    for i in goods_elements:
        title = i.get_attribute("title")
        titles.append(title)
    return titles

    def click_goods_all(self):
        """点击全部商品"""
        titles = self.get_goods_titles()
        for title in titles:
            good_loc = ("css selector", f"a[title='{title}']")
            self.click(good_loc)
            time.sleep(1)
            self.back()

